package com.ljkj.cordial.chat.ui.views;

import com.lanjiu.lib.imclient.bus.EventConstants;
import com.lanjiu.lib.imclient.bus.MessageEvent;
import com.lanjiu.lib.imclient.dto.user.RegisteredUserDto;
import com.lanjiu.lib.utils.log.Logger;
import com.ljkj.cordial.chat.ui.IView;

/**
 * @description:
 * @author: Panwei
 * @date: 2019/11/22 10:40
 */
public class ForgetPasswordView extends IView {

    private ForgetPassCallback mCallback;

    public ForgetPasswordView(ForgetPassCallback mCallback) {
        this.mCallback = mCallback;
    }

    public void doGetVerificationCode(String phone) {
        doSendRequest(EventConstants.Action.VERIFICATION_CODE_NO_LOGIN, phone);
    }

    public void doVerify(String userId, String phone, String captcha) {
        RegisteredUserDto registeredUser = new RegisteredUserDto();
        registeredUser.setUserId(userId);
        registeredUser.setPhone(phone);
        registeredUser.setCaptcha(captcha);
        doSendRequest(EventConstants.Action.RESET_SECRET_VERIFY, registeredUser.toJson());
    }

    public void doReset(String userId, String password) {
        RegisteredUserDto registeredUser = new RegisteredUserDto();
        registeredUser.setUserId(userId);
        registeredUser.setSecret(password);
        doSendRequest(EventConstants.Action.RESET_SECRET_NO_LOGIN, registeredUser.toJson());
    }

    @Override
    public void onMessageEventHandle(MessageEvent event) {
        Logger.print("ForgetPasswordView", event.toString());
        if (event.action() == EventConstants.Action.VERIFICATION_CODE) {
            if (null != mCallback)
                mCallback.onVerifyCodeCallback(event.code(), event.msg());
        } else if (event.action() == EventConstants.Action.RESET_SECRET_VERIFY) {
            if (null != mCallback)
                mCallback.onVerifyCallback(event.code(), event.msg());
        } else if (event.action() == EventConstants.Action.RESET_SECRET) {
            if (null != mCallback)
                mCallback.onResetCallback(event.code(), event.msg());
        }
    }

    public interface ForgetPassCallback {

        void onVerifyCodeCallback(int code, String msg);

        void onVerifyCallback(int code, String msg);

        void onResetCallback(int code, String msg);
    }
}
